/**
 * Created by jaliu on 2015/2/28.
 */

Schema = mongoose.Schema;

var lotteryMongoSchema = new Schema({
    lotteryName: String,
    url: String,
    lotteryDesc: String,
    lotteryStartDate: {type: Date, default: Date.now},
    lotteryEndDate: {type: Date, default: Date.now},
    numberOfTicketDigital: {type: Number, default: 6},
    totalNumberOfLuckyTicket: Number,
    totalNumberOfTicket: Number,
    community: {type: Schema.Types.ObjectId, ref: 'community'},

    weekLottery: [
        {
            startTime: Date,
            endTime: Date,
            isOpen: {type: Boolean, default: false},
            firstPrize: {type: String, default: 'ipad'},
            twoPrize: {type: String, default: 'camera'},
            threePrize: {type: String, default: 'power'},
            lotteryTickets: [{
                ticketValue: String,
                user: {type: Schema.Types.ObjectId, ref: 'user'},
                userName: String,
                phone: String,
                address: String,
                prize: String,
                ranking: {type: Number, default: 0},
                isLucky: {type: Boolean, default: false},
                giftSentFlag: {type: Boolean, default: false}
            }]
        }
    ],

    lotteryDrawType: {type: String, enum: ['weekly', 'monthly', 'specificDate']},
    weekDay: {type: Number, enum: [1, 2, 3, 4, 5, 6, 7]},
    time: Number,
//--WeekDay : //1-周一，2-周一，3-周三，4-周四，5-周五，6-周六，7-周日
    WeekDayTime: String,        //时间
    monthDay: Number,           //一月中的那一天
    monthDayTime: String,       //时间
    specificDateTime: Date,     //具体某个日期和时间
    dateCreated: {type: Date, default: Date.now},
    createdBy: {type: Schema.Types.ObjectId, ref: 'backoffice_adminusers'}
});
mongoose.model('backoffice_lotteries', lotteryMongoSchema, 'backoffice_lotteries');


var giftActivitySchema = new Schema({
    giftName: String,
    dateCreated: {type: Date, default: Date.now},
    community: {type: Schema.Types.ObjectId, ref: 'community'},
    users: [{
        user: {type: Schema.Types.ObjectId, ref: 'user'},
        mobilePhone: String,
        userName: String,
        roomUnit: String,
        roomNumber: String,
        apartmentDetail: String,
        timePeriodAvailable: String,
        dateCreated: {type: Date, default: Date.now}
    }]
});
mongoose.model('backoffice_giftActivities', giftActivitySchema, 'backoffice_giftActivities');

var participantsSchema = new Schema({
    user: {type: Schema.Types.ObjectId, ref: 'user'},
    mobilePhone: String,
    userName: String,
    address: String,
    roomUnit: String,
    roomNumber: String,
    dateCreated: {type: Date, default: Date.now}
});
mongoose.model('backoffice_participants', participantsSchema, 'backoffice_participants');